package com.godpaper.as9.commands
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	import com.godpaper.as9.bussiness.delegates.MessageDelegate;
	import com.godpaper.as9.events.GetMessageListEvent;
	import com.godpaper.as9.events.TryDeleteMessageEvent;
	import com.godpaper.as9.model.MessageModelLocator;
	import com.godpaper.as9.model.PhotoModelLocator;
	
	import mx.rpc.IResponder;

	public class TryDeleteMessageCommand extends CommandBase implements ICommand, IResponder
	{
		private var delegate:MessageDelegate;
		private var tryDeleteMessageEvent:TryDeleteMessageEvent;
		private var messageModel:MessageModelLocator = MessageModelLocator.getInstance();
		[Bindable]
		private var photoModel:PhotoModelLocator = PhotoModelLocator.getInstance(); 
		public function TryDeleteMessageCommand()
		{
			super();
			delegate = new MessageDelegate(this);
		}
		
		override public function execute(event:CairngormEvent):void
		{
			tryDeleteMessageEvent = TryDeleteMessageEvent(event);
			delegate.delete_(tryDeleteMessageEvent.mno);
		}
		
		override public function result(data:Object):void
		{
//			trace(data.result.info);
			if(data.result.info=="success")
			{
				CairngormEventDispatcher.getInstance().dispatchEvent(new GetMessageListEvent(photoModel.photoInfo.pno));
			}
		}
		
		
	}
}